<template>
  <!-- 第一种格式 -->
  <div
    class="postItem"
    v-if="data.images.length>=3"
  >
    <a :href="`/post/post?id=${data.id}`">
      <div class="
      head">{{data.title}}
      </div>
    </a>
    <a :href="`/post/post?id=${data.id}`">
      <p>{{data.summary}}</p>
    </a>
    <a :href="`/post/post?id=${data.id}`">
      <div class="pic">
        <img
          :src="data.images[0]"
          alt=""
        >
        <img
          :src="data.images[1]"
          alt=""
        >
        <img
          :src="data.images[2]"
          alt=""
        >
      </div>
    </a>
    <div class="footer">
      <div class="left">
        <span class="el-icon-location-information"></span>
        <span>{{(data.city&&data.city.name)||(data.city&&data.city.nickname)}}</span>
        <span>by</span>
        <span class="icon_head"><img
            :src="baseURL+(data.city&&data.account.defaultAvatar)"
            alt=""
          ></span>
        <span><a href="#">{{data.city&&data.account.nickname}}</a></span>
        <span class="el-icon-view"></span>
        <span>{{data.watch?data.watch:0}}</span>
      </div>
      <div class="right"><span>{{data.like?data.like:0}}</span>赞</div>
    </div>

  </div>
  <!-- 第二种格式 -->
  <div
    v-else-if="data.images.length==1||data.images.length==2"
    class="one"
  >
    <div class="o_left">
      <a :href="`/post/post?id=${data.id}`">
        <img
          :src="data.images[0]"
          alt=""
        >
      </a>
    </div>
    <div class="o_right">
      <a :href="`/post/post?id=${data.id}`">
        <div class="o_hear">{{data.title}}</div>
      </a>
      <a :href="`/post/post?id=${data.id}`">
        <p>{{data.summary}}</p>
      </a>
      <div class="footer">
        <div class="left">
          <span class="el-icon-location-information"></span>
          <span>{{(data.city&&data.city.name)||(data.city&&data.city.nickname)}}</span>
          <span>by</span>
          <span class="icon_head"><img
              :src="baseURL+(data.city&&data.account.defaultAvatar)"
              alt=""
            ></span>
          <span><a href="#">{{data.city&&data.account.nickname}}</a></span>
          <span class="el-icon-view"></span>
          <span>{{data.watch?data.watch:0}}</span>
        </div>
        <div class="right"><span>{{data.like?data.like:0}}</span>赞</div>
      </div>
    </div>

  </div>
  <!-- 第三种格式 -->
  <div
    v-else-if="data.images.length==0"
    class="zero"
  >
    <a :href="`/post/post?id=${data.id}`">
      <div class="header">{{data.title}}</div>
    </a>
    <a :href="`/post/post?id=${data.id}`">
      <p>{{data.summary}}</p>
    </a>
    <div class="footer">
      <div class="left">
        <span class="el-icon-location-information"></span>
        <span>{{(data.city&&data.city.name)||(data.city&&data.city.nickname)}}</span>
        <span>by</span>
        <span class="icon_head"><img
            :src="baseURL+(data.city&&data.account.defaultAvatar)"
            alt=""
          ></span>
        <span><a href="#">{{data.city&&data.account.nickname}}</a></span>
        <span class="el-icon-view"></span>
        <span>{{data.watch?data.watch:0}}</span>
      </div>
      <div class="right"><span>{{data.like?data.like:0}}</span>赞</div>
    </div>
  </div>
</template>

<script>
import myaxios from "@/utils/myaxios";
export default {
  props: ["data"],
  data() {
    return {
      baseURL: myaxios.defaults.baseURL,
      arr: [],
    };
  },
};
</script>

<style lang="less" scoped>
p {
  font-size: 14px;
  color: #666666;
  overflow: hidden;
  text-overflow: ellipsis;
  /* 弹性伸缩盒子模型显示 */
  display: -webkit-box;
  /* 限制在一个块元素显示的文本的行数 */
  -webkit-line-clamp: 3;
  /* 设置或检索伸缩盒对象的子元素的排列方式 */
  -webkit-box-orient: vertical;
}
.footer {
  display: flex;
  justify-content: space-between;
  .left {
    a {
      color: #ffa500;
    }
    font-size: 12px;
    color: #ccc;
    .icon_head {
      display: inline-block;
      width: 16px;
      height: 16px;
      img {
        width: 16px;
        height: 16px;
        border-radius: 8px;
      }
    }
  }
  .right {
    font-size: 12px;
    color: #ffc14f;
    span {
      margin-right: 5px;
    }
  }
}
.postItem {
  padding: 20px;
  border-bottom: 2px solid #f3f3f3;
  .head {
    height: 40px;
    line-height: 40px;
    font-size: 20px;
    white-space: nowrap;
    /* 2. 超出的隐藏 */
    overflow: hidden;
    /* 3. 文字溢出的时候，用省略号显示 */
    text-overflow: ellipsis;
    &:hover {
      color: #ffa500;
    }
  }

  .pic {
    display: flex;
    height: 140px;
    margin-top: 15px;
    margin-bottom: 15px;
    img {
      height: 100%;
      flex: 1;
    }
  }
}
.one {
  display: flex;
  padding: 20px;
  justify-content: space-between;
  border-bottom: 2px solid #f3f3f3;
  .o_left {
    width: 199px;
    height: 140px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .o_right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 450px;
    .o_hear {
      font-size: 16px;
      height: 28px;
      line-height: 28px;
      margin-bottom: 20px;
      white-space: nowrap;
      /* 2. 超出的隐藏 */
      overflow: hidden;
      /* 3. 文字溢出的时候，用省略号显示 */
      text-overflow: ellipsis;
      &:hover {
        color: #ffa500;
      }
    }
    .footer {
      margin-top: 20px;
    }
  }
}
.zero {
  height: 200px;
  width: 100%;
  padding: 20px 0;
  border-bottom: 2px solid #f3f3f3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .header {
    height: 30px;
    line-height: 30px;
    font-size: 20px;
    white-space: nowrap;
    /* 2. 超出的隐藏 */
    overflow: hidden;
    /* 3. 文字溢出的时候，用省略号显示 */
    text-overflow: ellipsis;
    &:hover {
      color: #ffa500;
    }
  }
  p {
    font-size: 16px;
    margin-top: -60px;
  }
}
</style>